home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3818 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  86 lines

  1. Newsgroups: comp.lang.c
  2. Path: in1.uu.net!robcad!usenet
  3. From: michael@robcad.uucp (Michael Zemmour)
  4. Subject: Re: division problem
  5. In-Reply-To: gumboot@airdmhor.gen.nz's message of 30 Jan 1996 05:14:50 +1300
  6. Message-ID: <MICHAEL.96Jan31131024@saturn.robcad.uucp>
  7. Sender: usenet@robcad.uucp (Pseudo usenet user for nntp)
  8. Organization: ROBCAD Ltd. Herzelia - Israel
  9. References: <31097D77.11AA@rain.org> <4eirpq$8ut@airdmhor.gen.nz>
  10. Date: Wed, 31 Jan 1996 11:10:24 GMT
  11.  
  12. In article <4eirpq$8ut@airdmhor.gen.nz> gumboot@airdmhor.gen.nz (Simon Hosie) writes:
  13.  
  14. > From: gumboot@airdmhor.gen.nz (Simon Hosie)
  15. > Newsgroups: comp.lang.c
  16. > Date: 30 Jan 1996 05:14:50 +1300
  17. > Organization: Airdmhor
  18. > tpaul:
  19. > > Can anyone show me why this does not work?  I am a beginner.
  20. >  1> #include <stdio.h>
  21. >  3> main ()
  22. >  4> {
  23. >  5>     int fahrenheit, celsius;
  24. >  7>     printf("Fahrenheit temperature =?";
  25. >  8>     scanf("%d",fahrenheit);
  26. >  9>     celsius = 5/9*(fahrenheit-32);
  27. > 10>     printf("Fahrenheit = %d, Celsius = %d", fahrenheit, celsius;
  28. > 11> }
  29.  
  30.  
  31.  
  32. #include <stdio.h>
  33.  
  34. main()
  35. {
  36.     int fahrenheit, celsius;
  37.     printf("Fahrenheit temperature = ?");
  38.     scanf("%d", &fahrenheit);
  39.     celsius = (int) (5.0/9.0*(fahrenheit-32));
  40.     printf("Fahrenheit = %d, Celsius = %d\n", fahrenheit, celsius);
  41. }
  42.  
  43.  
  44. Three things I noticed : 
  45.     1) scanf function accepts as argument only adress of variable.
  46.     In your case, the adresse of your integer variable. 
  47.  
  48.     2) celsius = (int) ...
  49.     The "celsius" variable is an integer and the computation
  50.     you make give you a float. You have to do what is called
  51.     a "casting", that means here to translate the float value 
  52.     to an integer value and to set it to your integer variable 
  53.     "celsius"
  54.     
  55.     3) (5/9 ...) This returns you the 0 value. I will be glad to 
  56.     understand why. Anyway, you may write instead
  57.       (5.0/9.0 ....)
  58.  
  59. Hope it helps .
  60.  
  61. ==============================================================================
  62. Michael Zemmour  
  63. ROBCAD/Man
  64. R&D Department
  65.  
  66. Tecnomatix Technologies Ltd             Tel:      972-9-594714
  67. Delta House                                       972-9-594777
  68. 16 Hagalim Avenue                       Fax:      972-9-544402
  69. Herzliya 46733                          Internet: michael%robcad@uunet.uu.net
  70. Israel                                  UUCP:     uunet!robcad!michael
  71. ==============================================================================
  72.  
  73. -- 
  74.  
  75.  
  76.                    >@)
  77.           Michael  (V(_
  78.          ===========^^\< ==
  79.  
  80.  
  81.